

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>ase.atoms &mdash; quippy 7ea04c5+ documentation</title>
  

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../_static/language_data.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "math|output_area", "processEscapes": true, "ignoreClass": "document", "inlineMath": [["$", "$"], ["\\(", "\\)"]]}})</script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/theme_overrides.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> quippy
          

          
            
            <img src="../../_static/hybrid.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                7ea04c5+
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
    
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to <code class="docutils literal notranslate"><span class="pre">quippy</span></code></a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install.html">Installation of QUIP and quippy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Tutorials/index.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quippy.html">Quippy library reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../visualisation.html">Visualisation Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fortran_wrapper.html">Appendix: wrapping Fortran 90 Code</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../teach_sparse.html">Command line options of the teach_sparse main program</a></li>
</ul>

            
          
    <p></p>
    <ul>
        <li><a href="../../genindex.html">Index</a></li>
        <li><a href="../../py-modindex.html">Module Index</a></li>
        <li><a href="../../search.html">Search Page</a></li>
        <li><a href="../index.html">Module Source Code</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">quippy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>ase.atoms</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for ase.atoms</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2008, 2009 CAMd</span>
<span class="c1"># (see accompanying license files for details).</span>

<span class="sd">&quot;&quot;&quot;Definition of the Atoms class.</span>

<span class="sd">This module defines the central object in the ASE package: the Atoms</span>
<span class="sd">object.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numbers</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="k">import</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">pi</span>
<span class="kn">import</span> <span class="nn">copy</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">import</span> <span class="nn">ase.units</span> <span class="k">as</span> <span class="nn">units</span>
<span class="kn">from</span> <span class="nn">ase.atom</span> <span class="k">import</span> <span class="n">Atom</span>
<span class="kn">from</span> <span class="nn">ase.constraints</span> <span class="k">import</span> <span class="n">FixConstraint</span><span class="p">,</span> <span class="n">FixBondLengths</span>
<span class="kn">from</span> <span class="nn">ase.data</span> <span class="k">import</span> <span class="n">atomic_masses</span>
<span class="kn">from</span> <span class="nn">ase.utils</span> <span class="k">import</span> <span class="n">basestring</span>
<span class="kn">from</span> <span class="nn">ase.geometry</span> <span class="k">import</span> <span class="p">(</span><span class="n">wrap_positions</span><span class="p">,</span> <span class="n">find_mic</span><span class="p">,</span> <span class="n">cellpar_to_cell</span><span class="p">,</span>
                          <span class="n">cell_to_cellpar</span><span class="p">,</span> <span class="n">complete_cell</span><span class="p">,</span> <span class="n">is_orthorhombic</span><span class="p">,</span>
                          <span class="n">get_angles</span><span class="p">,</span> <span class="n">get_distances</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">ase.symbols</span> <span class="k">import</span> <span class="n">Symbols</span><span class="p">,</span> <span class="n">symbols2numbers</span>


<span class="k">class</span> <span class="nc">Atoms</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Atoms object.</span>

<span class="sd">    The Atoms object can represent an isolated molecule, or a</span>
<span class="sd">    periodically repeated structure.  It has a unit cell and</span>
<span class="sd">    there may be periodic boundary conditions along any of the three</span>
<span class="sd">    unit cell axes.</span>
<span class="sd">    Information about the atoms (atomic numbers and position) is</span>
<span class="sd">    stored in ndarrays.  Optionally, there can be information about</span>
<span class="sd">    tags, momenta, masses, magnetic moments and charges.</span>

<span class="sd">    In order to calculate energies, forces and stresses, a calculator</span>
<span class="sd">    object has to attached to the atoms object.</span>

<span class="sd">    Parameters:</span>

<span class="sd">    symbols: str (formula) or list of str</span>
<span class="sd">        Can be a string formula, a list of symbols or a list of</span>
<span class="sd">        Atom objects.  Examples: &#39;H2O&#39;, &#39;COPt12&#39;, [&#39;H&#39;, &#39;H&#39;, &#39;O&#39;],</span>
<span class="sd">        [Atom(&#39;Ne&#39;, (x, y, z)), ...].</span>
<span class="sd">    positions: list of xyz-positions</span>
<span class="sd">        Atomic positions.  Anything that can be converted to an</span>
<span class="sd">        ndarray of shape (n, 3) will do: [(x1,y1,z1), (x2,y2,z2),</span>
<span class="sd">        ...].</span>
<span class="sd">    scaled_positions: list of scaled-positions</span>
<span class="sd">        Like positions, but given in units of the unit cell.</span>
<span class="sd">        Can not be set at the same time as positions.</span>
<span class="sd">    numbers: list of int</span>
<span class="sd">        Atomic numbers (use only one of symbols/numbers).</span>
<span class="sd">    tags: list of int</span>
<span class="sd">        Special purpose tags.</span>
<span class="sd">    momenta: list of xyz-momenta</span>
<span class="sd">        Momenta for all atoms.</span>
<span class="sd">    masses: list of float</span>
<span class="sd">        Atomic masses in atomic units.</span>
<span class="sd">    magmoms: list of float or list of xyz-values</span>
<span class="sd">        Magnetic moments.  Can be either a single value for each atom</span>
<span class="sd">        for collinear calculations or three numbers for each atom for</span>
<span class="sd">        non-collinear calculations.</span>
<span class="sd">    charges: list of float</span>
<span class="sd">        Initial atomic charges.</span>
<span class="sd">    cell: 3x3 matrix or length 3 or 6 vector</span>
<span class="sd">        Unit cell vectors.  Can also be given as just three</span>
<span class="sd">        numbers for orthorhombic cells, or 6 numbers, where</span>
<span class="sd">        first three are lengths of unit cell vectors, and the</span>
<span class="sd">        other three are angles between them (in degrees), in following order:</span>
<span class="sd">        [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)].</span>
<span class="sd">        First vector will lie in x-direction, second in xy-plane,</span>
<span class="sd">        and the third one in z-positive subspace.</span>
<span class="sd">        Default value: [0, 0, 0].</span>
<span class="sd">    celldisp: Vector</span>
<span class="sd">        Unit cell displacement vector. To visualize a displaced cell</span>
<span class="sd">        around the center of mass of a Systems of atoms. Default value</span>
<span class="sd">        = (0,0,0)</span>
<span class="sd">    pbc: one or three bool</span>
<span class="sd">        Periodic boundary conditions flags.  Examples: True,</span>
<span class="sd">        False, 0, 1, (1, 1, 0), (True, False, False).  Default</span>
<span class="sd">        value: False.</span>
<span class="sd">    constraint: constraint object(s)</span>
<span class="sd">        Used for applying one or more constraints during structure</span>
<span class="sd">        optimization.</span>
<span class="sd">    calculator: calculator object</span>
<span class="sd">        Used to attach a calculator for calculating energies and atomic</span>
<span class="sd">        forces.</span>
<span class="sd">    info: dict of key-value pairs</span>
<span class="sd">        Dictionary of key-value pairs with additional information</span>
<span class="sd">        about the system.  The following keys may be used by ase:</span>

<span class="sd">          - spacegroup: Spacegroup instance</span>
<span class="sd">          - unit_cell: &#39;conventional&#39; | &#39;primitive&#39; | int | 3 ints</span>
<span class="sd">          - adsorbate_info: Information about special adsorption sites</span>

<span class="sd">        Items in the info attribute survives copy and slicing and can</span>
<span class="sd">        be stored in and retrieved from trajectory files given that the</span>
<span class="sd">        key is a string, the value is JSON-compatible and, if the value is a</span>
<span class="sd">        user-defined object, its base class is importable.  One should</span>
<span class="sd">        not make any assumptions about the existence of keys.</span>

<span class="sd">    Examples:</span>

<span class="sd">    These three are equivalent:</span>

<span class="sd">    &gt;&gt;&gt; d = 1.104  # N2 bondlength</span>
<span class="sd">    &gt;&gt;&gt; a = Atoms(&#39;N2&#39;, [(0, 0, 0), (0, 0, d)])</span>
<span class="sd">    &gt;&gt;&gt; a = Atoms(numbers=[7, 7], positions=[(0, 0, 0), (0, 0, d)])</span>
<span class="sd">    &gt;&gt;&gt; a = Atoms([Atom(&#39;N&#39;, (0, 0, 0)), Atom(&#39;N&#39;, (0, 0, d))])</span>

<span class="sd">    FCC gold:</span>

<span class="sd">    &gt;&gt;&gt; a = 4.05  # Gold lattice constant</span>
<span class="sd">    &gt;&gt;&gt; b = a / 2</span>
<span class="sd">    &gt;&gt;&gt; fcc = Atoms(&#39;Au&#39;,</span>
<span class="sd">    ...             cell=[(0, b, b), (b, 0, b), (b, b, 0)],</span>
<span class="sd">    ...             pbc=True)</span>

<span class="sd">    Hydrogen wire:</span>

<span class="sd">    &gt;&gt;&gt; d = 0.9  # H-H distance</span>
<span class="sd">    &gt;&gt;&gt; h = Atoms(&#39;H&#39;, positions=[(0, 0, 0)],</span>
<span class="sd">    ...           cell=(d, 0, 0),</span>
<span class="sd">    ...           pbc=(1, 0, 0))</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">numbers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">tags</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">momenta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">masses</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">magmoms</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">scaled_positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">cell</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">celldisp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">constraint</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">calculator</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">info</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>

        <span class="n">atoms</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="s1">&#39;get_positions&#39;</span><span class="p">):</span>
            <span class="n">atoms</span> <span class="o">=</span> <span class="n">symbols</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">elif</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="ow">and</span>
              <span class="nb">len</span><span class="p">(</span><span class="n">symbols</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">symbols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">Atom</span><span class="p">)):</span>
            <span class="c1"># Get data from a list or tuple of Atom objects:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">[[</span><span class="n">atom</span><span class="o">.</span><span class="n">get_raw</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span>
                    <span class="p">[</span><span class="s1">&#39;position&#39;</span><span class="p">,</span> <span class="s1">&#39;number&#39;</span><span class="p">,</span> <span class="s1">&#39;tag&#39;</span><span class="p">,</span> <span class="s1">&#39;momentum&#39;</span><span class="p">,</span>
                     <span class="s1">&#39;mass&#39;</span><span class="p">,</span> <span class="s1">&#39;magmom&#39;</span><span class="p">,</span> <span class="s1">&#39;charge&#39;</span><span class="p">]]</span>
            <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">atoms</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># Get data from another Atoms object:</span>
            <span class="k">if</span> <span class="n">scaled_positions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">NotImplementedError</span>
            <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">numbers</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">numbers</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_atomic_numbers</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">positions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">positions</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">tags</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">atoms</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">):</span>
                <span class="n">tags</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_tags</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">momenta</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">atoms</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="s1">&#39;momenta&#39;</span><span class="p">):</span>
                <span class="n">momenta</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_momenta</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">magmoms</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">atoms</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="s1">&#39;initial_magmoms&#39;</span><span class="p">):</span>
                <span class="n">magmoms</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_initial_magnetic_moments</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">masses</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">atoms</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="s1">&#39;masses&#39;</span><span class="p">):</span>
                <span class="n">masses</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">charges</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">atoms</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="s1">&#39;initial_charges&#39;</span><span class="p">):</span>
                <span class="n">charges</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_initial_charges</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">cell</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">cell</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">celldisp</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">celldisp</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_celldisp</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">pbc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">pbc</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_pbc</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">constraint</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">constraint</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">constraints</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">calculator</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">calculator</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_calculator</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">info</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">info</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">info</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">numbers</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">positions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">natoms</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">positions</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">scaled_positions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">natoms</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">scaled_positions</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">natoms</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">numbers</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">natoms</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">new_array</span><span class="p">(</span><span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="n">numbers</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">numbers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s1">&#39;Use only one of &quot;symbols&quot; and &quot;numbers&quot;.&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">new_array</span><span class="p">(</span><span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="n">symbols2numbers</span><span class="p">(</span><span class="n">symbols</span><span class="p">),</span> <span class="nb">int</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">cell</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_cell</span><span class="p">(</span><span class="n">cell</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">celldisp</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">celldisp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_celldisp</span><span class="p">(</span><span class="n">celldisp</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">positions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">scaled_positions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">positions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]),</span> <span class="mi">3</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">number_of_lattice_vectors</span> <span class="o">==</span> <span class="mi">3</span>
                <span class="n">positions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">scaled_positions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">scaled_positions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Both scaled and cartesian positions set!&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">new_array</span><span class="p">(</span><span class="s1">&#39;positions&#39;</span><span class="p">,</span> <span class="n">positions</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_constraint</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_tags</span><span class="p">(</span><span class="n">default</span><span class="p">(</span><span class="n">tags</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_masses</span><span class="p">(</span><span class="n">default</span><span class="p">(</span><span class="n">masses</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_initial_magnetic_moments</span><span class="p">(</span><span class="n">default</span><span class="p">(</span><span class="n">magmoms</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_initial_charges</span><span class="p">(</span><span class="n">default</span><span class="p">(</span><span class="n">charges</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">pbc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_pbc</span><span class="p">(</span><span class="n">pbc</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_momenta</span><span class="p">(</span><span class="n">default</span><span class="p">(</span><span class="n">momenta</span><span class="p">,</span> <span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)),</span>
                         <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">info</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_calculator</span><span class="p">(</span><span class="n">calculator</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">Symbols</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">numbers</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.set_calculator"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_calculator">[docs]</a>    <span class="k">def</span> <span class="nf">set_calculator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">calc</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Attach calculator object.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="o">=</span> <span class="n">calc</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">calc</span><span class="p">,</span> <span class="s1">&#39;set_atoms&#39;</span><span class="p">):</span>
            <span class="n">calc</span><span class="o">.</span><span class="n">set_atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_calculator"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_calculator">[docs]</a>    <span class="k">def</span> <span class="nf">get_calculator</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get currently attached calculator object.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span></div>

    <span class="k">def</span> <span class="nf">_del_calculator</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="n">calc</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">get_calculator</span><span class="p">,</span> <span class="n">set_calculator</span><span class="p">,</span> <span class="n">_del_calculator</span><span class="p">,</span>
                    <span class="n">doc</span><span class="o">=</span><span class="s1">&#39;Calculator object.&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">number_of_lattice_vectors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of (non-zero) lattice vectors.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>

<div class="viewcode-block" id="Atoms.set_constraint"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_constraint">[docs]</a>    <span class="k">def</span> <span class="nf">set_constraint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constraint</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Apply one or more constrains.</span>

<span class="sd">        The *constraint* argument must be one constraint object or a</span>
<span class="sd">        list of constraint objects.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">constraint</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="n">constraint</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="p">[</span><span class="n">constraint</span><span class="p">]</span></div>

    <span class="k">def</span> <span class="nf">_get_constraints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span>

    <span class="k">def</span> <span class="nf">_del_constraints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">constraints</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_constraints</span><span class="p">,</span> <span class="n">set_constraint</span><span class="p">,</span> <span class="n">_del_constraints</span><span class="p">,</span>
                           <span class="s1">&#39;Constraints of the atoms.&#39;</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.set_cell"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_cell">[docs]</a>    <span class="k">def</span> <span class="nf">set_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell</span><span class="p">,</span> <span class="n">scale_atoms</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set unit cell vectors.</span>

<span class="sd">        Parameters:</span>

<span class="sd">        cell: 3x3 matrix or length 3 or 6 vector</span>
<span class="sd">            Unit cell.  A 3x3 matrix (the three unit cell vectors) or</span>
<span class="sd">            just three numbers for an orthorhombic cell. Another option is</span>
<span class="sd">            6 numbers, which describes unit cell with lengths of unit cell</span>
<span class="sd">            vectors and with angles between them (in degrees), in following</span>
<span class="sd">            order: [len(a), len(b), len(c), angle(b,c), angle(a,c),</span>
<span class="sd">            angle(a,b)].  First vector will lie in x-direction, second in</span>
<span class="sd">            xy-plane, and the third one in z-positive subspace.</span>
<span class="sd">        scale_atoms: bool</span>
<span class="sd">            Fix atomic positions or move atoms with the unit cell?</span>
<span class="sd">            Default behavior is to *not* move the atoms (scale_atoms=False).</span>

<span class="sd">        Examples:</span>

<span class="sd">        Two equivalent ways to define an orthorhombic cell:</span>

<span class="sd">        &gt;&gt;&gt; atoms = Atoms(&#39;He&#39;)</span>
<span class="sd">        &gt;&gt;&gt; a, b, c = 7, 7.5, 8</span>
<span class="sd">        &gt;&gt;&gt; atoms.set_cell([a, b, c])</span>
<span class="sd">        &gt;&gt;&gt; atoms.set_cell([(a, 0, 0), (0, b, 0), (0, 0, c)])</span>

<span class="sd">        FCC unit cell:</span>

<span class="sd">        &gt;&gt;&gt; atoms.set_cell([(0, b, b), (b, 0, b), (b, b, 0)])</span>

<span class="sd">        Hexagonal unit cell:</span>

<span class="sd">        &gt;&gt;&gt; atoms.set_cell([a, a, c, 90, 90, 120])</span>

<span class="sd">        Rhombohedral unit cell:</span>

<span class="sd">        &gt;&gt;&gt; alpha = 77</span>
<span class="sd">        &gt;&gt;&gt; atoms.set_cell([a, a, a, alpha, alpha, alpha])</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cell</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">cell</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">3</span><span class="p">,):</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">(</span><span class="n">cell</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">cell</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">6</span><span class="p">,):</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="n">cellpar_to_cell</span><span class="p">(</span><span class="n">cell</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">cell</span><span class="o">.</span><span class="n">shape</span> <span class="o">!=</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Cell must be length 3 sequence, length 6 &#39;</span>
                             <span class="s1">&#39;sequence or 3x3 matrix!&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">scale_atoms</span><span class="p">:</span>
            <span class="n">M</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">(</span><span class="n">complete</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
                                <span class="n">complete_cell</span><span class="p">(</span><span class="n">cell</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span> <span class="o">=</span> <span class="n">cell</span></div>

<div class="viewcode-block" id="Atoms.set_celldisp"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_celldisp">[docs]</a>    <span class="k">def</span> <span class="nf">set_celldisp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">celldisp</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the unit cell displacement vectors.&quot;&quot;&quot;</span>
        <span class="n">celldisp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">celldisp</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_celldisp</span> <span class="o">=</span> <span class="n">celldisp</span></div>

<div class="viewcode-block" id="Atoms.get_celldisp"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_celldisp">[docs]</a>    <span class="k">def</span> <span class="nf">get_celldisp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the unit cell displacement vectors.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_celldisp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="Atoms.get_cell"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_cell">[docs]</a>    <span class="k">def</span> <span class="nf">get_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">complete</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the three unit cell vectors as a 3x3 ndarray.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">complete</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">complete_cell</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="Atoms.get_cell_lengths_and_angles"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_cell_lengths_and_angles">[docs]</a>    <span class="k">def</span> <span class="nf">get_cell_lengths_and_angles</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get unit cell parameters. Sequence of 6 numbers.</span>

<span class="sd">        First three are unit cell vector lengths and second three</span>
<span class="sd">        are angles between them::</span>

<span class="sd">            [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)]</span>

<span class="sd">        in degrees.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">cell_to_cellpar</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_reciprocal_cell"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_reciprocal_cell">[docs]</a>    <span class="k">def</span> <span class="nf">get_reciprocal_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the three reciprocal lattice vectors as a 3x3 ndarray.</span>

<span class="sd">        Note that the commonly used factor of 2 pi for Fourier</span>
<span class="sd">        transforms is not included here.&quot;&quot;&quot;</span>

        <span class="n">rec_unit_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">pinv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">())</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">rec_unit_cell</span></div>

<div class="viewcode-block" id="Atoms.set_pbc"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_pbc">[docs]</a>    <span class="k">def</span> <span class="nf">set_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pbc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set periodic boundary condition flags.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pbc</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="p">(</span><span class="n">pbc</span><span class="p">,)</span> <span class="o">*</span> <span class="mi">3</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pbc</span><span class="p">,</span> <span class="nb">bool</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_pbc"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_pbc">[docs]</a>    <span class="k">def</span> <span class="nf">get_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get periodic boundary condition flags.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="nf">new_array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add new array.</span>

<span class="sd">        If *shape* is not *None*, the shape of *a* will be checked.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">dtype</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="s1">&#39;C&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">shape</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,)</span> <span class="o">+</span> <span class="n">shape</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">a</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="s1">&#39;C_CONTIGUOUS&#39;</span><span class="p">]:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ascontiguousarray</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">b</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Array has wrong length: </span><span class="si">%d</span><span class="s1"> != </span><span class="si">%d</span><span class="s1">.&#39;</span> <span class="o">%</span>
                                 <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">b</span><span class="p">)))</span>
            <span class="k">break</span>

        <span class="k">if</span> <span class="n">shape</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Array has wrong shape </span><span class="si">%s</span><span class="s1"> != </span><span class="si">%s</span><span class="s1">.&#39;</span> <span class="o">%</span>
                             <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">shape</span><span class="p">)))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span>

<div class="viewcode-block" id="Atoms.get_array"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_array">[docs]</a>    <span class="k">def</span> <span class="nf">get_array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get an array.</span>

<span class="sd">        Returns a copy unless the optional argument copy is false.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">copy</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span></div>

<div class="viewcode-block" id="Atoms.set_array"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_array">[docs]</a>    <span class="k">def</span> <span class="nf">set_array</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update array.</span>

<span class="sd">        If *shape* is not *None*, the shape of *a* will be checked.</span>
<span class="sd">        If *a* is *None*, then the array is deleted.&quot;&quot;&quot;</span>

        <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">b</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">new_array</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">shape</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">shape</span> <span class="o">!=</span> <span class="n">b</span><span class="o">.</span><span class="n">shape</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Array has wrong shape </span><span class="si">%s</span><span class="s1"> != </span><span class="si">%s</span><span class="s1">.&#39;</span> <span class="o">%</span>
                                     <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span>
                <span class="n">b</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">a</span></div>

<div class="viewcode-block" id="Atoms.has"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.has">[docs]</a>    <span class="k">def</span> <span class="nf">has</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Check for existence of array.</span>

<span class="sd">        name must be one of: &#39;tags&#39;, &#39;momenta&#39;, &#39;masses&#39;, &#39;initial_magmoms&#39;,</span>
<span class="sd">        &#39;initial_charges&#39;.&quot;&quot;&quot;</span>
        <span class="c1"># XXX extend has to calculator properties</span>
        <span class="k">return</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span></div>

    <span class="k">def</span> <span class="nf">set_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numbers</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set atomic numbers.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="n">numbers</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="p">())</span>

<div class="viewcode-block" id="Atoms.get_atomic_numbers"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_atomic_numbers">[docs]</a>    <span class="k">def</span> <span class="nf">get_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get integer array of atomic numbers.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="Atoms.get_chemical_symbols"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_chemical_symbols">[docs]</a>    <span class="k">def</span> <span class="nf">get_chemical_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get list of chemical symbol strings.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">symbols</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">set_chemical_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set chemical symbols.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="n">symbols2numbers</span><span class="p">(</span><span class="n">symbols</span><span class="p">),</span> <span class="nb">int</span><span class="p">,</span> <span class="p">())</span>

<div class="viewcode-block" id="Atoms.get_chemical_formula"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_chemical_formula">[docs]</a>    <span class="k">def</span> <span class="nf">get_chemical_formula</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;hill&#39;</span><span class="p">,</span> <span class="n">empirical</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the chemical formula as a string based on the chemical symbols.</span>

<span class="sd">        Parameters:</span>

<span class="sd">        mode: str</span>
<span class="sd">            There are three different modes available:</span>

<span class="sd">            &#39;all&#39;: The list of chemical symbols are contracted to a string,</span>
<span class="sd">            e.g. [&#39;C&#39;, &#39;H&#39;, &#39;H&#39;, &#39;H&#39;, &#39;O&#39;, &#39;H&#39;] becomes &#39;CHHHOH&#39;.</span>

<span class="sd">            &#39;reduce&#39;: The same as &#39;all&#39; where repeated elements are contracted</span>
<span class="sd">            to a single symbol and a number, e.g. &#39;CHHHOCHHH&#39; is reduced to</span>
<span class="sd">            &#39;CH3OCH3&#39;.</span>

<span class="sd">            &#39;hill&#39;: The list of chemical symbols are contracted to a string</span>
<span class="sd">            following the Hill notation (alphabetical order with C and H</span>
<span class="sd">            first), e.g. &#39;CHHHOCHHH&#39; is reduced to &#39;C2H6O&#39; and &#39;SOOHOHO&#39; to</span>
<span class="sd">            &#39;H2O4S&#39;. This is default.</span>

<span class="sd">            &#39;metal&#39;: The list of chemical symbols (alphabetical metals,</span>
<span class="sd">            and alphabetical non-metals)</span>

<span class="sd">        empirical, bool (optional, default=False)</span>
<span class="sd">            Divide the symbol counts by their greatest common divisor to yield</span>
<span class="sd">            an empirical formula. Only for mode `metal` and `hill`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">symbols</span><span class="o">.</span><span class="n">get_chemical_formula</span><span class="p">(</span><span class="n">mode</span><span class="p">,</span> <span class="n">empirical</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.set_tags"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_tags">[docs]</a>    <span class="k">def</span> <span class="nf">set_tags</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tags</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set tags for all atoms. If only one tag is supplied, it is</span>
<span class="sd">        applied to all atoms.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tags</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">tags</span> <span class="o">=</span> <span class="p">[</span><span class="n">tags</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">,</span> <span class="n">tags</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="p">())</span></div>

<div class="viewcode-block" id="Atoms.get_tags"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_tags">[docs]</a>    <span class="k">def</span> <span class="nf">get_tags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get integer array of tags.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;tags&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;tags&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="nb">int</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.set_momenta"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_momenta">[docs]</a>    <span class="k">def</span> <span class="nf">set_momenta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">momenta</span><span class="p">,</span> <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set momenta.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">apply_constraint</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span>
           <span class="n">momenta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">):</span>
            <span class="n">momenta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">momenta</span><span class="p">)</span>  <span class="c1"># modify a copy</span>
            <span class="k">for</span> <span class="n">constraint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="s1">&#39;adjust_momenta&#39;</span><span class="p">):</span>
                    <span class="n">constraint</span><span class="o">.</span><span class="n">adjust_momenta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">momenta</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;momenta&#39;</span><span class="p">,</span> <span class="n">momenta</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,))</span></div>

<div class="viewcode-block" id="Atoms.set_velocities"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_velocities">[docs]</a>    <span class="k">def</span> <span class="nf">set_velocities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">velocities</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the momenta by specifying the velocities.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_momenta</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span> <span class="o">*</span> <span class="n">velocities</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_momenta"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_momenta">[docs]</a>    <span class="k">def</span> <span class="nf">get_momenta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of momenta.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;momenta&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;momenta&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="mi">3</span><span class="p">))</span></div>

<div class="viewcode-block" id="Atoms.set_masses"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_masses">[docs]</a>    <span class="k">def</span> <span class="nf">set_masses</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">masses</span><span class="o">=</span><span class="s1">&#39;defaults&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set atomic masses in atomic mass units.</span>

<span class="sd">        The array masses should contain a list of masses.  In case</span>
<span class="sd">        the masses argument is not given or for those elements of the</span>
<span class="sd">        masses list that are None, standard values are set.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">masses</span><span class="p">,</span> <span class="n">basestring</span><span class="p">)</span> <span class="ow">and</span> <span class="n">masses</span> <span class="o">==</span> <span class="s1">&#39;defaults&#39;</span><span class="p">:</span>
            <span class="n">masses</span> <span class="o">=</span> <span class="n">atomic_masses</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]]</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">masses</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="n">newmasses</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">m</span><span class="p">,</span> <span class="n">Z</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">masses</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]):</span>
                <span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">newmasses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">atomic_masses</span><span class="p">[</span><span class="n">Z</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">newmasses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
            <span class="n">masses</span> <span class="o">=</span> <span class="n">newmasses</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;masses&#39;</span><span class="p">,</span> <span class="n">masses</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="p">())</span></div>

<div class="viewcode-block" id="Atoms.get_masses"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_masses">[docs]</a>    <span class="k">def</span> <span class="nf">get_masses</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of masses in atomic mass units.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;masses&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;masses&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">atomic_masses</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]]</span></div>

<div class="viewcode-block" id="Atoms.set_initial_magnetic_moments"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_initial_magnetic_moments">[docs]</a>    <span class="k">def</span> <span class="nf">set_initial_magnetic_moments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">magmoms</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the initial magnetic moments.</span>

<span class="sd">        Use either one or three numbers for every atom (collinear</span>
<span class="sd">        or non-collinear spins).&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">magmoms</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;initial_magmoms&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">magmoms</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">magmoms</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;initial_magmoms&#39;</span><span class="p">,</span> <span class="n">magmoms</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span>
                           <span class="n">magmoms</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span></div>

<div class="viewcode-block" id="Atoms.get_initial_magnetic_moments"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_initial_magnetic_moments">[docs]</a>    <span class="k">def</span> <span class="nf">get_initial_magnetic_moments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of initial magnetic moments.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;initial_magmoms&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;initial_magmoms&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span></div>

<div class="viewcode-block" id="Atoms.get_magnetic_moments"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_magnetic_moments">[docs]</a>    <span class="k">def</span> <span class="nf">get_magnetic_moments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get calculated local magnetic moments.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_magnetic_moments</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_magnetic_moment"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_magnetic_moment">[docs]</a>    <span class="k">def</span> <span class="nf">get_magnetic_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get calculated total magnetic moment.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_magnetic_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.set_initial_charges"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_initial_charges">[docs]</a>    <span class="k">def</span> <span class="nf">set_initial_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the initial charges.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">charges</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;initial_charges&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;initial_charges&#39;</span><span class="p">,</span> <span class="n">charges</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="p">())</span></div>

<div class="viewcode-block" id="Atoms.get_initial_charges"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_initial_charges">[docs]</a>    <span class="k">def</span> <span class="nf">get_initial_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of initial charges.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;initial_charges&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;initial_charges&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span></div>

<div class="viewcode-block" id="Atoms.get_charges"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_charges">[docs]</a>    <span class="k">def</span> <span class="nf">get_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get calculated charges.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">ase.calculators.calculator</span> <span class="k">import</span> <span class="n">PropertyNotImplementedError</span>
            <span class="k">raise</span> <span class="n">PropertyNotImplementedError</span></div>

<div class="viewcode-block" id="Atoms.set_positions"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_positions">[docs]</a>    <span class="k">def</span> <span class="nf">set_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">newpositions</span><span class="p">,</span> <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set positions, honoring any constraints. To ignore constraints,</span>
<span class="sd">        use *apply_constraint=False*.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="ow">and</span> <span class="n">apply_constraint</span><span class="p">:</span>
            <span class="n">newpositions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">newpositions</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">constraint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">:</span>
                <span class="n">constraint</span><span class="o">.</span><span class="n">adjust_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">newpositions</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="s1">&#39;positions&#39;</span><span class="p">,</span> <span class="n">newpositions</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,))</span></div>

<div class="viewcode-block" id="Atoms.get_positions"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_positions">[docs]</a>    <span class="k">def</span> <span class="nf">get_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">wrap</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of positions. If wrap==True, wraps atoms back</span>
<span class="sd">        into unit cell.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">wrap</span><span class="p">:</span>
            <span class="n">scaled</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_scaled_positions</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">scaled</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="Atoms.get_potential_energy"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_potential_energy">[docs]</a>    <span class="k">def</span> <span class="nf">get_potential_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">force_consistent</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                             <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate potential energy.</span>

<span class="sd">        Ask the attached calculator to calculate the potential energy and</span>
<span class="sd">        apply constraints.  Use *apply_constraint=False* to get the raw</span>
<span class="sd">        forces.</span>

<span class="sd">        When supported by the calculator, either the energy extrapolated</span>
<span class="sd">        to zero Kelvin or the energy consistent with the forces (the free</span>
<span class="sd">        energy) can be returned.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">force_consistent</span><span class="p">:</span>
            <span class="n">energy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_potential_energy</span><span class="p">(</span>
                <span class="bp">self</span><span class="p">,</span> <span class="n">force_consistent</span><span class="o">=</span><span class="n">force_consistent</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">energy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_potential_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">apply_constraint</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">constraint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="s1">&#39;adjust_potential_energy&#39;</span><span class="p">):</span>
                    <span class="n">energy</span> <span class="o">+=</span> <span class="n">constraint</span><span class="o">.</span><span class="n">adjust_potential_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">energy</span></div>

<div class="viewcode-block" id="Atoms.get_potential_energies"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_potential_energies">[docs]</a>    <span class="k">def</span> <span class="nf">get_potential_energies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate the potential energies of all the atoms.</span>

<span class="sd">        Only available with calculators supporting per-atom energies</span>
<span class="sd">        (e.g. classical potentials).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_potential_energies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_kinetic_energy"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_kinetic_energy">[docs]</a>    <span class="k">def</span> <span class="nf">get_kinetic_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the kinetic energy.&quot;&quot;&quot;</span>
        <span class="n">momenta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;momenta&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">momenta</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="mf">0.0</span>
        <span class="k">return</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">vdot</span><span class="p">(</span><span class="n">momenta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_velocities</span><span class="p">())</span></div>

<div class="viewcode-block" id="Atoms.get_velocities"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_velocities">[docs]</a>    <span class="k">def</span> <span class="nf">get_velocities</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get array of velocities.&quot;&quot;&quot;</span>
        <span class="n">momenta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;momenta&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">momenta</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;masses&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">m</span> <span class="o">=</span> <span class="n">atomic_masses</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="n">momenta</span> <span class="o">/</span> <span class="n">m</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_total_energy"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_total_energy">[docs]</a>    <span class="k">def</span> <span class="nf">get_total_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the total energy - potential plus kinetic energy.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_potential_energy</span><span class="p">()</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_kinetic_energy</span><span class="p">()</span></div>

<div class="viewcode-block" id="Atoms.get_forces"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_forces">[docs]</a>    <span class="k">def</span> <span class="nf">get_forces</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">md</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate atomic forces.</span>

<span class="sd">        Ask the attached calculator to calculate the forces and apply</span>
<span class="sd">        constraints.  Use *apply_constraint=False* to get the raw</span>
<span class="sd">        forces.</span>

<span class="sd">        For molecular dynamics (md=True) we don&#39;t apply the constraint</span>
<span class="sd">        to the forces but to the momenta.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="n">forces</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_forces</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">apply_constraint</span><span class="p">:</span>
            <span class="c1"># We need a special md flag here because for MD we want</span>
            <span class="c1"># to skip real constraints but include special &quot;constraints&quot;</span>
            <span class="c1"># Like Hookean.</span>
            <span class="k">for</span> <span class="n">constraint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">md</span> <span class="ow">or</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="s1">&#39;adjust_potential_energy&#39;</span><span class="p">):</span>
                    <span class="n">constraint</span><span class="o">.</span><span class="n">adjust_forces</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">forces</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">forces</span></div>

<div class="viewcode-block" id="Atoms.get_stress"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_stress">[docs]</a>    <span class="k">def</span> <span class="nf">get_stress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">voigt</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate stress tensor.</span>

<span class="sd">        Returns an array of the six independent components of the</span>
<span class="sd">        symmetric stress tensor, in the traditional Voigt order</span>
<span class="sd">        (xx, yy, zz, yz, xz, xy) or as a 3x3 matrix.  Default is Voigt</span>
<span class="sd">        order.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>

        <span class="n">stress</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_stress</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">shape</span> <span class="o">=</span> <span class="n">stress</span><span class="o">.</span><span class="n">shape</span>

        <span class="k">if</span> <span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s1">&#39;Converting 3x3 stress tensor from </span><span class="si">%s</span><span class="s1"> &#39;</span> <span class="o">%</span>
                          <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span>
                          <span class="s1">&#39;calculator to the required Voigt form.&#39;</span><span class="p">)</span>
            <span class="n">stress</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">stress</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">stress</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">stress</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
                               <span class="n">stress</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">stress</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">stress</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">6</span><span class="p">,)</span>

        <span class="k">if</span> <span class="n">voigt</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">stress</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">xx</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="n">zz</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">xz</span><span class="p">,</span> <span class="n">xy</span> <span class="o">=</span> <span class="n">stress</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([(</span><span class="n">xx</span><span class="p">,</span> <span class="n">xy</span><span class="p">,</span> <span class="n">xz</span><span class="p">),</span>
                             <span class="p">(</span><span class="n">xy</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="n">yz</span><span class="p">),</span>
                             <span class="p">(</span><span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">zz</span><span class="p">)])</span></div>

<div class="viewcode-block" id="Atoms.get_stresses"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_stresses">[docs]</a>    <span class="k">def</span> <span class="nf">get_stresses</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate the stress-tensor of all the atoms.</span>

<span class="sd">        Only available with calculators supporting per-atom energies and</span>
<span class="sd">        stresses (e.g. classical potentials).  Even for such calculators</span>
<span class="sd">        there is a certain arbitrariness in defining per-atom stresses.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_stresses</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_dipole_moment"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_dipole_moment">[docs]</a>    <span class="k">def</span> <span class="nf">get_dipole_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate the electric dipole moment for the atoms object.</span>

<span class="sd">        Only available for calculators which has a get_dipole_moment()</span>
<span class="sd">        method.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Atoms object has no calculator.&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="n">get_dipole_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a copy.&quot;&quot;&quot;</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">cell</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="p">,</span> <span class="n">info</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">)</span>

        <span class="n">atoms</span><span class="o">.</span><span class="n">arrays</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">atoms</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">atoms</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">atoms</span>

    <span class="k">def</span> <span class="nf">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">])</span>

<div class="viewcode-block" id="Atoms.get_number_of_atoms"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_number_of_atoms">[docs]</a>    <span class="k">def</span> <span class="nf">get_number_of_atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns the global number of atoms in a distributed-atoms parallel</span>
<span class="sd">        simulation.</span>

<span class="sd">        DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING!</span>

<span class="sd">        Equivalent to len(atoms) in the standard ASE Atoms class.  You should</span>
<span class="sd">        normally use len(atoms) instead.  This function&#39;s only purpose is to</span>
<span class="sd">        make compatibility between ASE and Asap easier to maintain by having a</span>
<span class="sd">        few places in ASE use this function instead.  It is typically only</span>
<span class="sd">        when counting the global number of degrees of freedom or in similar</span>
<span class="sd">        situations.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">tokens</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">N</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">N</span> <span class="o">&lt;=</span> <span class="mi">60</span><span class="p">:</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_chemical_formula</span><span class="p">(</span><span class="s1">&#39;reduce&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_chemical_formula</span><span class="p">(</span><span class="s1">&#39;hill&#39;</span><span class="p">)</span>
        <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;symbols=&#39;</span><span class="si">{0}</span><span class="s2">&#39;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">symbols</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="o">.</span><span class="n">any</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;pbc=</span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;pbc=</span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">any</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">is_orthorhombic</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">):</span>
                <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">diagonal</span><span class="p">()</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;cell=</span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cell</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">,</span> <span class="s1">&#39;positions&#39;</span><span class="p">]:</span>
                <span class="k">continue</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{0}</span><span class="s1">=...&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">constraint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">constraint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;constraint=</span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">constraint</span><span class="p">)))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">tokens</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;calculator=</span><span class="si">{0}</span><span class="s1">(...)&#39;</span>
                          <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_calc</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span>

        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">{0}</span><span class="s1">(</span><span class="si">{1}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tokens</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">atoms</span> <span class="o">+=</span> <span class="n">other</span>
        <span class="k">return</span> <span class="n">atoms</span>

    <span class="k">def</span> <span class="nf">extend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Extend atoms object by appending atoms from *other*.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Atom</span><span class="p">):</span>
            <span class="n">other</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">other</span><span class="p">])</span>

        <span class="n">n1</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">n2</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a1</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n2</span><span class="p">,)</span> <span class="o">+</span> <span class="n">a1</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">a1</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span>
            <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="n">a1</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;masses&#39;</span><span class="p">:</span>
                <span class="n">a2</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a2</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">a2</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[</span><span class="n">n1</span><span class="p">:]</span> <span class="o">=</span> <span class="n">a2</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a2</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="n">n1</span> <span class="o">+</span> <span class="n">n2</span><span class="p">,)</span> <span class="o">+</span> <span class="n">a2</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">a2</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span>
            <span class="n">a</span><span class="p">[</span><span class="n">n1</span><span class="p">:]</span> <span class="o">=</span> <span class="n">a2</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;masses&#39;</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()[:</span><span class="n">n1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">a</span><span class="p">[:</span><span class="n">n1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span>

    <span class="fm">__iadd__</span> <span class="o">=</span> <span class="n">extend</span>

<div class="viewcode-block" id="Atoms.append"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.append">[docs]</a>    <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atom</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Append atom to end.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">([</span><span class="n">atom</span><span class="p">]))</span></div>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a subset of the atoms.</span>

<span class="sd">        i -- scalar integer, list of integers, or slice object</span>
<span class="sd">        describing which atoms to return.</span>

<span class="sd">        If i is a scalar, return an Atom object. If i is a list or a</span>
<span class="sd">        slice, return an Atoms object with the same cell, pbc, and</span>
<span class="sd">        other associated info as the original Atoms object. The</span>
<span class="sd">        indices of the constraints will be shuffled so that they match</span>
<span class="sd">        the indexing in the subset returned.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Integral</span><span class="p">):</span>
            <span class="n">natoms</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="o">-</span><span class="n">natoms</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">&gt;=</span> <span class="n">natoms</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s1">&#39;Index out of range.&#39;</span><span class="p">)</span>

            <span class="k">return</span> <span class="n">Atom</span><span class="p">(</span><span class="n">atoms</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="n">i</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># Make sure a list of booleans will work correctly and not be</span>
            <span class="c1"># interpreted at 0 and 1 indices.</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="kn">import</span> <span class="nn">copy</span>

        <span class="n">conadd</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># Constraints need to be deepcopied, but only the relevant ones.</span>
        <span class="k">for</span> <span class="n">con</span> <span class="ow">in</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">con</span><span class="p">,</span> <span class="p">(</span><span class="n">FixConstraint</span><span class="p">,</span> <span class="n">FixBondLengths</span><span class="p">)):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">con</span><span class="o">.</span><span class="n">index_shuffle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
                    <span class="n">conadd</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">con</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                    <span class="k">pass</span>

        <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">cell</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="p">,</span> <span class="n">info</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">,</span>
                               <span class="c1"># should be communicated to the slice as well</span>
                               <span class="n">celldisp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_celldisp</span><span class="p">)</span>
        <span class="c1"># TODO: Do we need to shuffle indices in adsorbate_info too?</span>

        <span class="n">atoms</span><span class="o">.</span><span class="n">arrays</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">atoms</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

        <span class="n">atoms</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="n">conadd</span>
        <span class="k">return</span> <span class="n">atoms</span>

    <span class="k">def</span> <span class="nf">__delitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="kn">from</span> <span class="nn">ase.constraints</span> <span class="k">import</span> <span class="n">FixAtoms</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">FixAtoms</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Remove constraint using set_constraint() &#39;</span>
                                   <span class="s1">&#39;before deleting atoms.&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># Make sure a list of booleans will work correctly and not be</span>
            <span class="c1"># interpreted at 0 and 1 indices.</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">n</span><span class="p">)[</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                <span class="n">i</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">constraints</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">:</span>
                <span class="n">c</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">delete_atoms</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">constraints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="n">constraints</span>

        <span class="n">mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="nb">bool</span><span class="p">)</span>
        <span class="n">mask</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>

<div class="viewcode-block" id="Atoms.pop"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.pop">[docs]</a>    <span class="k">def</span> <span class="nf">pop</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove and return atom at index *i* (default last).&quot;&quot;&quot;</span>
        <span class="n">atom</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="n">atom</span><span class="o">.</span><span class="n">cut_reference_to_atoms</span><span class="p">()</span>
        <span class="k">del</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">atom</span></div>

    <span class="k">def</span> <span class="nf">__imul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;In-place repeat of atoms.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">m</span> <span class="o">=</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">vec</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">x</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">vec</span><span class="o">.</span><span class="n">any</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Cannot repeat along undefined lattice &#39;</span>
                                 <span class="s1">&#39;vector&#39;</span><span class="p">)</span>

        <span class="n">M</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="n">M</span><span class="p">,)</span> <span class="o">+</span> <span class="p">(</span><span class="mi">1</span><span class="p">,)</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span>

        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">i0</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">m0</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="k">for</span> <span class="n">m1</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                <span class="k">for</span> <span class="n">m2</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">]):</span>
                    <span class="n">i1</span> <span class="o">=</span> <span class="n">i0</span> <span class="o">+</span> <span class="n">n</span>
                    <span class="n">positions</span><span class="p">[</span><span class="n">i0</span><span class="p">:</span><span class="n">i1</span><span class="p">]</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">((</span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">)</span>
                    <span class="n">i0</span> <span class="o">=</span> <span class="n">i1</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">constraints</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">m</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">[</span><span class="n">c</span><span class="p">]</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)])</span>

        <span class="k">return</span> <span class="bp">self</span>

<div class="viewcode-block" id="Atoms.repeat"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.repeat">[docs]</a>    <span class="k">def</span> <span class="nf">repeat</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create new repeated atoms object.</span>

<span class="sd">        The *rep* argument should be a sequence of three positive</span>
<span class="sd">        integers like *(2,3,1)* or a single integer (*r*) equivalent</span>
<span class="sd">        to *(r,r,r)*.&quot;&quot;&quot;</span>

        <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">atoms</span> <span class="o">*=</span> <span class="n">rep</span>
        <span class="k">return</span> <span class="n">atoms</span></div>

    <span class="fm">__mul__</span> <span class="o">=</span> <span class="n">repeat</span>

<div class="viewcode-block" id="Atoms.translate"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.translate">[docs]</a>    <span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">displacement</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Translate atomic positions.</span>

<span class="sd">        The displacement argument can be a float an xyz vector or an</span>
<span class="sd">        nx3 array (where n is the number of atoms).&quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">displacement</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.center"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.center">[docs]</a>    <span class="k">def</span> <span class="nf">center</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vacuum</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">about</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Center atoms in unit cell.</span>

<span class="sd">        Centers the atoms in the unit cell, so there is the same</span>
<span class="sd">        amount of vacuum on all sides.</span>

<span class="sd">        vacuum: float (default: None)</span>
<span class="sd">            If specified adjust the amount of vacuum when centering.</span>
<span class="sd">            If vacuum=10.0 there will thus be 10 Angstrom of vacuum</span>
<span class="sd">            on each side.</span>
<span class="sd">        axis: int or sequence of ints</span>
<span class="sd">            Axis or axes to act on.  Default: Act on all axes.</span>
<span class="sd">        about: float or array (default: None)</span>
<span class="sd">            If specified, center the atoms about &lt;about&gt;.</span>
<span class="sd">            I.e., about=(0., 0., 0.) (or just &quot;about=0.&quot;, interpreted</span>
<span class="sd">            identically), to center about the origin.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Find the orientations of the faces of the unit cell</span>
        <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">(</span><span class="n">complete</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">dirs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros_like</span><span class="p">(</span><span class="n">cell</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
            <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">cell</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">],</span> <span class="n">cell</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">2</span><span class="p">])</span>
            <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>  <span class="c1"># normalize</span>
            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&lt;</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*=</span> <span class="o">-</span><span class="mi">1</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">axes</span> <span class="o">=</span> <span class="p">(</span><span class="n">axis</span><span class="p">,)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">axes</span> <span class="o">=</span> <span class="n">axis</span>

        <span class="c1"># if vacuum and any(self.pbc[x] for x in axes):</span>
        <span class="c1">#     warnings.warn(</span>
        <span class="c1">#         &#39;You are adding vacuum along a periodic direction!&#39;)</span>

        <span class="c1"># Now, decide how much each basis vector should be made longer</span>
        <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">longer</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">shift</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">axes</span><span class="p">:</span>
            <span class="n">p0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="k">else</span> <span class="mi">0</span>
            <span class="n">p1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="k">else</span> <span class="mi">0</span>
            <span class="n">height</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">vacuum</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">lng</span> <span class="o">=</span> <span class="p">(</span><span class="n">p1</span> <span class="o">-</span> <span class="n">p0</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">vacuum</span><span class="p">)</span> <span class="o">-</span> <span class="n">height</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">lng</span> <span class="o">=</span> <span class="mf">0.0</span>  <span class="c1"># Do not change unit cell size!</span>
            <span class="n">top</span> <span class="o">=</span> <span class="n">lng</span> <span class="o">+</span> <span class="n">height</span> <span class="o">-</span> <span class="n">p1</span>
            <span class="n">shf</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">top</span> <span class="o">-</span> <span class="n">p0</span><span class="p">)</span>
            <span class="n">cosphi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">dirs</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">],</span>
                                                               <span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
            <span class="n">longer</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">lng</span> <span class="o">/</span> <span class="n">cosphi</span>
            <span class="n">shift</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">shf</span> <span class="o">/</span> <span class="n">cosphi</span>

        <span class="c1"># Now, do it!</span>
        <span class="n">translation</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">axes</span><span class="p">:</span>
            <span class="n">nowlen</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
            <span class="k">if</span> <span class="n">vacuum</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">any</span><span class="p">():</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">longer</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="n">nowlen</span><span class="p">)</span>
                <span class="n">translation</span> <span class="o">+=</span> <span class="n">shift</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">cell</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="n">nowlen</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">translation</span>

        <span class="c1"># Optionally, translate to center about a point in space.</span>
        <span class="k">if</span> <span class="n">about</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">vector</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cell</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">positions</span> <span class="o">-=</span> <span class="n">vector</span> <span class="o">/</span> <span class="mf">2.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">positions</span> <span class="o">+=</span> <span class="n">about</span></div>

<div class="viewcode-block" id="Atoms.get_center_of_mass"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_center_of_mass">[docs]</a>    <span class="k">def</span> <span class="nf">get_center_of_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scaled</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the center of mass.</span>

<span class="sd">        If scaled=True the center of mass in scaled coordinates</span>
<span class="sd">        is returned.&quot;&quot;&quot;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>
        <span class="n">com</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">])</span> <span class="o">/</span> <span class="n">m</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">scaled</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">com</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">com</span></div>

<div class="viewcode-block" id="Atoms.get_moments_of_inertia"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_moments_of_inertia">[docs]</a>    <span class="k">def</span> <span class="nf">get_moments_of_inertia</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vectors</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the moments of inertia along the principal axes.</span>

<span class="sd">        The three principal moments of inertia are computed from the</span>
<span class="sd">        eigenvalues of the symmetric inertial tensor. Periodic boundary</span>
<span class="sd">        conditions are ignored. Units of the moments of inertia are</span>
<span class="sd">        amu*angstrom**2.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">com</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_center_of_mass</span><span class="p">()</span>
        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span>
        <span class="n">positions</span> <span class="o">-=</span> <span class="n">com</span>  <span class="c1"># translate center of mass to origin</span>
        <span class="n">masses</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_masses</span><span class="p">()</span>

        <span class="c1"># Initialize elements of the inertial tensor</span>
        <span class="n">I11</span> <span class="o">=</span> <span class="n">I22</span> <span class="o">=</span> <span class="n">I33</span> <span class="o">=</span> <span class="n">I12</span> <span class="o">=</span> <span class="n">I13</span> <span class="o">=</span> <span class="n">I23</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)):</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">positions</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">m</span> <span class="o">=</span> <span class="n">masses</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

            <span class="n">I11</span> <span class="o">+=</span> <span class="n">m</span> <span class="o">*</span> <span class="p">(</span><span class="n">y</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">z</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
            <span class="n">I22</span> <span class="o">+=</span> <span class="n">m</span> <span class="o">*</span> <span class="p">(</span><span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">z</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
            <span class="n">I33</span> <span class="o">+=</span> <span class="n">m</span> <span class="o">*</span> <span class="p">(</span><span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
            <span class="n">I12</span> <span class="o">+=</span> <span class="o">-</span><span class="n">m</span> <span class="o">*</span> <span class="n">x</span> <span class="o">*</span> <span class="n">y</span>
            <span class="n">I13</span> <span class="o">+=</span> <span class="o">-</span><span class="n">m</span> <span class="o">*</span> <span class="n">x</span> <span class="o">*</span> <span class="n">z</span>
            <span class="n">I23</span> <span class="o">+=</span> <span class="o">-</span><span class="n">m</span> <span class="o">*</span> <span class="n">y</span> <span class="o">*</span> <span class="n">z</span>

        <span class="n">I</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">I11</span><span class="p">,</span> <span class="n">I12</span><span class="p">,</span> <span class="n">I13</span><span class="p">],</span>
                      <span class="p">[</span><span class="n">I12</span><span class="p">,</span> <span class="n">I22</span><span class="p">,</span> <span class="n">I23</span><span class="p">],</span>
                      <span class="p">[</span><span class="n">I13</span><span class="p">,</span> <span class="n">I23</span><span class="p">,</span> <span class="n">I33</span><span class="p">]])</span>

        <span class="n">evals</span><span class="p">,</span> <span class="n">evecs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">eigh</span><span class="p">(</span><span class="n">I</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">vectors</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">evals</span><span class="p">,</span> <span class="n">evecs</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">evals</span></div>

<div class="viewcode-block" id="Atoms.get_angular_momentum"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_angular_momentum">[docs]</a>    <span class="k">def</span> <span class="nf">get_angular_momentum</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get total angular momentum with respect to the center of mass.&quot;&quot;&quot;</span>
        <span class="n">com</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_center_of_mass</span><span class="p">()</span>
        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span>
        <span class="n">positions</span> <span class="o">-=</span> <span class="n">com</span>  <span class="c1"># translate center of mass to origin</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">positions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_momenta</span><span class="p">())</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">rotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">v</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">rotate_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Rotate atoms based on a vector and an angle, or two vectors.</span>

<span class="sd">        Parameters:</span>

<span class="sd">        a = None:</span>
<span class="sd">            Angle that the atoms is rotated around the vecor &#39;v&#39;. &#39;a&#39;</span>
<span class="sd">            can also be a vector and then &#39;a&#39; is rotated</span>
<span class="sd">            into &#39;v&#39;.</span>

<span class="sd">        v:</span>
<span class="sd">            Vector to rotate the atoms around. Vectors can be given as</span>
<span class="sd">            strings: &#39;x&#39;, &#39;-x&#39;, &#39;y&#39;, ... .</span>

<span class="sd">        center = (0, 0, 0):</span>
<span class="sd">            The center is kept fixed under the rotation. Use &#39;COM&#39; to fix</span>
<span class="sd">            the center of mass, &#39;COP&#39; to fix the center of positions or</span>
<span class="sd">            &#39;COU&#39; to fix the center of cell.</span>

<span class="sd">        rotate_cell = False:</span>
<span class="sd">            If true the cell is also rotated.</span>

<span class="sd">        Examples:</span>

<span class="sd">        Rotate 90 degrees around the z-axis, so that the x-axis is</span>
<span class="sd">        rotated into the y-axis:</span>

<span class="sd">        &gt;&gt;&gt; atoms = Atoms()</span>
<span class="sd">        &gt;&gt;&gt; atoms.rotate(90, &#39;z&#39;)</span>
<span class="sd">        &gt;&gt;&gt; atoms.rotate(90, (0, 0, 1))</span>
<span class="sd">        &gt;&gt;&gt; atoms.rotate(-90, &#39;-z&#39;)</span>
<span class="sd">        &gt;&gt;&gt; atoms.rotate(&#39;x&#39;, &#39;y&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="nb">int</span><span class="p">)):</span>
            <span class="c1"># old API maybe?</span>
            <span class="n">warning</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;Please use new API: &#39;</span>
                       <span class="s1">&#39;atoms_obj.rotate(a, v) &#39;</span>
                       <span class="s1">&#39;where v is a vector to rotate around and &#39;</span>
                       <span class="s1">&#39;a is the angle in degrees.&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="nb">int</span><span class="p">)):</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">warning</span><span class="p">)</span>
                <span class="n">a</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">v</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span><span class="p">,</span> <span class="n">a</span>
            <span class="k">elif</span> <span class="n">v</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">warning</span><span class="p">)</span>
                <span class="n">v</span> <span class="o">=</span> <span class="n">a</span>
                <span class="n">a</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">assert</span> <span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                <span class="n">a</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">v</span><span class="p">,</span> <span class="n">a</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">a</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

        <span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">string2vector</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">a</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span>  <span class="c1"># old API</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="nb">int</span><span class="p">)):</span>
            <span class="n">a</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
            <span class="n">v</span> <span class="o">/=</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">v2</span> <span class="o">=</span> <span class="n">string2vector</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">v</span> <span class="o">/=</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="n">v2</span> <span class="o">/=</span> <span class="n">norm</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">v2</span><span class="p">)</span>
            <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">v2</span><span class="p">)</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="c1"># In case *v* and *a* are parallel, np.cross(v, v2) vanish</span>
            <span class="c1"># and can&#39;t be used as a rotation axis. However, in this</span>
            <span class="c1"># case any rotation axis perpendicular to v2 will do.</span>
            <span class="n">eps</span> <span class="o">=</span> <span class="mf">1e-7</span>
            <span class="k">if</span> <span class="n">s</span> <span class="o">&lt;</span> <span class="n">eps</span><span class="p">:</span>
                <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">v2</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">eps</span><span class="p">:</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">v2</span><span class="p">)</span>
                <span class="k">assert</span> <span class="n">norm</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">eps</span>
            <span class="k">elif</span> <span class="n">s</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">v</span> <span class="o">/=</span> <span class="n">s</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">center</span><span class="p">,</span> <span class="n">basestring</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;com&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_center_of_mass</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;cop&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;cou&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Cannot interpret center&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">center</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">center</span><span class="p">)</span>

        <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="n">center</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">][:]</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="n">p</span> <span class="o">-</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">s</span> <span class="o">*</span> <span class="n">v</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">v</span><span class="p">),</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">c</span><span class="p">)</span> <span class="o">*</span> <span class="n">v</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">center</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rotate_cell</span><span class="p">:</span>
            <span class="n">rotcell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span>
            <span class="n">rotcell</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="n">rotcell</span> <span class="o">-</span>
                          <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">rotcell</span><span class="p">,</span> <span class="n">s</span> <span class="o">*</span> <span class="n">v</span><span class="p">)</span> <span class="o">+</span>
                          <span class="n">np</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">rotcell</span><span class="p">,</span> <span class="n">v</span><span class="p">),</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">c</span><span class="p">)</span> <span class="o">*</span> <span class="n">v</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_cell</span><span class="p">(</span><span class="n">rotcell</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">rotate_euler</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">phi</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">theta</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">psi</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
            <span class="s1">&#39;Please use this method instead: &#39;</span>
            <span class="s1">&#39;euler_rotate(phi=0, theta=0, psi=0, center=(0, 0, 0)) &#39;</span>
            <span class="s1">&#39;where the angles are given in degrees&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">euler_rotate</span><span class="p">(</span><span class="n">phi</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span><span class="p">,</span> <span class="n">theta</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span><span class="p">,</span> <span class="n">psi</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span><span class="p">,</span>
                          <span class="n">center</span><span class="p">)</span>

<div class="viewcode-block" id="Atoms.euler_rotate"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.euler_rotate">[docs]</a>    <span class="k">def</span> <span class="nf">euler_rotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">phi</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">theta</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">psi</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;Rotate atoms via Euler angles (in degrees).</span>

<span class="sd">        See e.g http://mathworld.wolfram.com/EulerAngles.html for explanation.</span>

<span class="sd">        Parameters:</span>

<span class="sd">        center :</span>
<span class="sd">            The point to rotate about. A sequence of length 3 with the</span>
<span class="sd">            coordinates, or &#39;COM&#39; to select the center of mass, &#39;COP&#39; to</span>
<span class="sd">            select center of positions or &#39;COU&#39; to select center of cell.</span>
<span class="sd">        phi :</span>
<span class="sd">            The 1st rotation angle around the z axis.</span>
<span class="sd">        theta :</span>
<span class="sd">            Rotation around the x axis.</span>
<span class="sd">        psi :</span>
<span class="sd">            2nd rotation around the z axis.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">center</span><span class="p">,</span> <span class="n">basestring</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;com&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_center_of_mass</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;cop&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">center</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;cou&#39;</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Cannot interpret center&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">center</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">center</span><span class="p">)</span>

        <span class="n">phi</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="n">theta</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="n">psi</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>

        <span class="c1"># First move the molecule to the origin In contrast to MATLAB,</span>
        <span class="c1"># numpy broadcasts the smaller array to the larger row-wise,</span>
        <span class="c1"># so there is no need to play with the Kronecker product.</span>
        <span class="n">rcoords</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span> <span class="o">-</span> <span class="n">center</span>
        <span class="c1"># First Euler rotation about z in matrix form</span>
        <span class="n">D</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(((</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="mf">0.</span><span class="p">),</span>
                      <span class="p">(</span><span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="mf">0.</span><span class="p">),</span>
                      <span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">)))</span>
        <span class="c1"># Second Euler rotation about x:</span>
        <span class="n">C</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(((</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">),</span>
                      <span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)),</span>
                      <span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">))))</span>
        <span class="c1"># Third Euler rotation, 2nd rotation about z:</span>
        <span class="n">B</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(((</span><span class="n">cos</span><span class="p">(</span><span class="n">psi</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">psi</span><span class="p">),</span> <span class="mf">0.</span><span class="p">),</span>
                      <span class="p">(</span><span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">psi</span><span class="p">),</span> <span class="n">cos</span><span class="p">(</span><span class="n">psi</span><span class="p">),</span> <span class="mf">0.</span><span class="p">),</span>
                      <span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">)))</span>
        <span class="c1"># Total Euler rotation</span>
        <span class="n">A</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">))</span>
        <span class="c1"># Do the rotation</span>
        <span class="n">rcoords</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">rcoords</span><span class="p">))</span>
        <span class="c1"># Move back to the rotation point</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">positions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">rcoords</span><span class="p">)</span> <span class="o">+</span> <span class="n">center</span></div>

<div class="viewcode-block" id="Atoms.get_dihedral"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_dihedral">[docs]</a>    <span class="k">def</span> <span class="nf">get_dihedral</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a3</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a4</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate dihedral angle.</span>

<span class="sd">        Calculate dihedral angle (in degrees) between the vectors a1-&gt;a2</span>
<span class="sd">        and a3-&gt;a4.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention and calculate the</span>
<span class="sd">        angle across periodic boundaries.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">a2</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># Old way - use radians</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s1">&#39;Please use new API (which will return the angle in degrees): &#39;</span>
                <span class="s1">&#39;atoms_obj.get_dihedral(a1,a2,a3,a4)*pi/180 instead of &#39;</span>
                <span class="s1">&#39;atoms_obj.get_dihedral([a1,a2,a3,a4])&#39;</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">a3</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a4</span> <span class="ow">is</span> <span class="kc">None</span>
            <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span> <span class="o">=</span> <span class="n">a1</span>
            <span class="n">f</span> <span class="o">=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="mi">1</span>

        <span class="c1"># vector 1-&gt;2, 2-&gt;3, 3-&gt;4 and their normalized cross products:</span>
        <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a1</span><span class="p">]</span>
        <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span>
        <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a4</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">find_mic</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">bxa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
        <span class="n">bxa</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">bxa</span><span class="p">)</span>
        <span class="n">cxb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
        <span class="n">cxb</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">cxb</span><span class="p">)</span>
        <span class="n">angle</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vdot</span><span class="p">(</span><span class="n">bxa</span><span class="p">,</span> <span class="n">cxb</span><span class="p">)</span>
        <span class="c1"># check for numerical trouble due to finite precision:</span>
        <span class="k">if</span> <span class="n">angle</span> <span class="o">&lt;</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
            <span class="n">angle</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="k">if</span> <span class="n">angle</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">angle</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">angle</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arccos</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">vdot</span><span class="p">(</span><span class="n">bxa</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">angle</span> <span class="o">=</span> <span class="mi">360</span> <span class="o">-</span> <span class="n">angle</span>
        <span class="k">return</span> <span class="n">angle</span> <span class="o">*</span> <span class="n">f</span></div>

    <span class="k">def</span> <span class="nf">_masked_rotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">axis</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">mask</span><span class="p">):</span>
        <span class="c1"># do rotation of subgroup by copying it to temporary atoms object</span>
        <span class="c1"># and then rotating that</span>
        <span class="c1">#</span>
        <span class="c1"># recursive object definition might not be the most elegant thing,</span>
        <span class="c1"># more generally useful might be a rotation function with a mask?</span>
        <span class="n">group</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">mask</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">group</span> <span class="o">+=</span> <span class="bp">self</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="n">group</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="o">-</span><span class="n">center</span><span class="p">)</span>
        <span class="n">group</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">diff</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span><span class="p">,</span> <span class="n">axis</span><span class="p">)</span>
        <span class="n">group</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="n">center</span><span class="p">)</span>
        <span class="c1"># set positions in original atoms object</span>
        <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">mask</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">position</span>
                <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>

<div class="viewcode-block" id="Atoms.set_dihedral"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_dihedral">[docs]</a>    <span class="k">def</span> <span class="nf">set_dihedral</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a3</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a4</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                     <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the dihedral angle (degrees) between vectors a1-&gt;a2 and</span>
<span class="sd">        a3-&gt;a4 by changing the atom indexed by a4.</span>

<span class="sd">        If mask is not None, all the atoms described in mask</span>
<span class="sd">        (read: the entire subgroup) are moved. Alternatively to the mask,</span>
<span class="sd">        the indices of the atoms to be rotated can be supplied. If both</span>
<span class="sd">        *mask* and *indices* are given, *indices* overwrites *mask*.</span>

<span class="sd">        **Important**: If *mask* or *indices* is given and does not contain</span>
<span class="sd">        *a4*, *a4* will NOT be moved. In most cases you therefore want</span>
<span class="sd">        to include *a4* in *mask*/*indices*.</span>

<span class="sd">        Example: the following defines a very crude</span>
<span class="sd">        ethane-like molecule and twists one half of it by 30 degrees.</span>

<span class="sd">        &gt;&gt;&gt; atoms = Atoms(&#39;HHCCHH&#39;, [[-1, 1, 0], [-1, -1, 0], [0, 0, 0],</span>
<span class="sd">        ...                          [1, 0, 0], [2, 1, 0], [2, -1, 0]])</span>
<span class="sd">        &gt;&gt;&gt; atoms.set_dihedral(1, 2, 3, 4, 210, mask=[0, 0, 0, 1, 1, 1])</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">angle</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s1">&#39;Please use new API: &#39;</span>
                <span class="s1">&#39;atoms_obj.set_dihedral(a1,a2,a3,a4,angle) &#39;</span>
                <span class="s1">&#39;where angle is given in degrees&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">angle</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">angle</span> <span class="o">=</span> <span class="n">a2</span>
                <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">mask</span> <span class="o">=</span> <span class="n">a3</span>
                    <span class="k">if</span> <span class="n">indices</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="n">indices</span> <span class="o">=</span> <span class="n">a4</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">assert</span> <span class="n">a2</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a3</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a4</span> <span class="ow">is</span> <span class="kc">None</span>
            <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span> <span class="o">=</span> <span class="n">a1</span>

        <span class="c1"># if not provided, set mask to the last atom in the</span>
        <span class="c1"># dihedral description</span>
        <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">indices</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
            <span class="n">mask</span><span class="p">[</span><span class="n">a4</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">elif</span> <span class="n">indices</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="p">[</span><span class="n">index</span> <span class="ow">in</span> <span class="n">indices</span> <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))]</span>

        <span class="c1"># compute necessary in dihedral change, from current value</span>
        <span class="n">current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_dihedral</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span><span class="p">)</span> <span class="o">*</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="n">angle</span> <span class="o">-</span> <span class="n">current</span>
        <span class="n">axis</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span>
        <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_masked_rotate</span><span class="p">(</span><span class="n">center</span><span class="p">,</span> <span class="n">axis</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">mask</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.rotate_dihedral"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.rotate_dihedral">[docs]</a>    <span class="k">def</span> <span class="nf">rotate_dihedral</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a3</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a4</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                        <span class="n">angle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Rotate dihedral angle.</span>

<span class="sd">        Same usage as in :meth:`ase.Atoms.set_dihedral`: Rotate a group by a</span>
<span class="sd">        predefined dihedral angle, starting from its current configuration.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="n">start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_dihedral</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_dihedral</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span><span class="p">,</span> <span class="n">angle</span> <span class="o">+</span> <span class="n">start</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s1">&#39;Please use new API: &#39;</span>
                <span class="s1">&#39;atoms_obj.rotate_dihedral(a1,a2,a3,a4,angle) &#39;</span>
                <span class="s1">&#39;where angle is given in degrees&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">angle</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">angle</span> <span class="o">=</span> <span class="n">a2</span>
                <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">indices</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">mask</span> <span class="o">=</span> <span class="n">a3</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">assert</span> <span class="n">a2</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a3</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a4</span> <span class="ow">is</span> <span class="kc">None</span>
            <span class="n">start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_dihedral</span><span class="p">(</span><span class="n">a1</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_dihedral</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">angle</span> <span class="o">+</span> <span class="n">start</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_angle"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_angle">[docs]</a>    <span class="k">def</span> <span class="nf">get_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get angle formed by three atoms.</span>

<span class="sd">        calculate angle in degrees between the vectors a2-&gt;a1 and</span>
<span class="sd">        a2-&gt;a3.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention and calculate the</span>
<span class="sd">        angle across periodic boundaries.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">]])</span>

        <span class="n">a1s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]]</span>
        <span class="n">a2s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]]</span>
        <span class="n">a3s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]]</span>

        <span class="n">v12</span> <span class="o">=</span> <span class="n">a1s</span> <span class="o">-</span> <span class="n">a2s</span>
        <span class="n">v32</span> <span class="o">=</span> <span class="n">a3s</span> <span class="o">-</span> <span class="n">a2s</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pbc</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

        <span class="k">return</span> <span class="n">get_angles</span><span class="p">(</span><span class="n">v12</span><span class="p">,</span> <span class="n">v32</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="n">pbc</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>


<div class="viewcode-block" id="Atoms.get_angles"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_angles">[docs]</a>    <span class="k">def</span> <span class="nf">get_angles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get angle formed by three atoms for multiple groupings.</span>

<span class="sd">        calculate angle in degrees between vectors between atoms a2-&gt;a1</span>
<span class="sd">        and a2-&gt;a3, where a1, a2, and a3 are in each row of indices.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention and calculate</span>
<span class="sd">        the angle across periodic boundaries.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">indices</span><span class="p">)</span>

        <span class="n">a1s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]]</span>
        <span class="n">a2s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]]</span>
        <span class="n">a3s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">indices</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]]</span>

        <span class="n">v12</span> <span class="o">=</span> <span class="n">a1s</span> <span class="o">-</span> <span class="n">a2s</span>
        <span class="n">v32</span> <span class="o">=</span> <span class="n">a3s</span> <span class="o">-</span> <span class="n">a2s</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pbc</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

        <span class="k">return</span> <span class="n">get_angles</span><span class="p">(</span><span class="n">v12</span><span class="p">,</span> <span class="n">v32</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="n">pbc</span><span class="p">)</span></div>


<div class="viewcode-block" id="Atoms.set_angle"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_angle">[docs]</a>    <span class="k">def</span> <span class="nf">set_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">a3</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">add</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set angle (in degrees) formed by three atoms.</span>

<span class="sd">        Sets the angle between vectors *a2*-&gt;*a1* and *a2*-&gt;*a3*.</span>

<span class="sd">        If *add* is `True`, the angle will be changed by the value given.</span>

<span class="sd">        Same usage as in :meth:`ase.Atoms.set_dihedral`. If *mask* and *indices*</span>
<span class="sd">        are given, *indices* overwrites *mask*. If *mask* and *indices* are not set,</span>
<span class="sd">        only *a3* is moved.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="c1"># old API (uses radians)</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s1">&#39;Please use new API: &#39;</span>
                <span class="s1">&#39;atoms_obj.set_angle(a1,a2,a3,angle) &#39;</span>
                <span class="s1">&#39;where angle is given in degrees&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">angle</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">angle</span> <span class="o">=</span> <span class="n">a2</span>
                <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">mask</span> <span class="o">=</span> <span class="n">a3</span>
                <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span> <span class="o">=</span> <span class="n">a1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">assert</span> <span class="n">a2</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">a3</span> <span class="ow">is</span> <span class="kc">None</span>
            <span class="n">angle</span> <span class="o">*=</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span>

        <span class="c1"># If not provided, set mask to the last atom in the angle description</span>
        <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">indices</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
            <span class="n">mask</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">elif</span> <span class="n">indices</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="p">[</span><span class="n">index</span> <span class="ow">in</span> <span class="n">indices</span> <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))]</span>

        <span class="k">if</span> <span class="n">add</span><span class="p">:</span>
            <span class="n">diff</span> <span class="o">=</span> <span class="n">angle</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Compute necessary in angle change, from current value</span>
            <span class="n">diff</span> <span class="o">=</span> <span class="n">angle</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_angle</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">)</span>

        <span class="n">diff</span> <span class="o">*=</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">180</span>
        <span class="c1"># Do rotation of subgroup by copying it to temporary atoms object and</span>
        <span class="c1"># then rotating that</span>
        <span class="n">v10</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span>
        <span class="n">v12</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a3</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span>
        <span class="n">v10</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">v10</span><span class="p">)</span>
        <span class="n">v12</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">v12</span><span class="p">)</span>
        <span class="n">axis</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">v10</span><span class="p">,</span> <span class="n">v12</span><span class="p">)</span>
        <span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[</span><span class="n">a2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_masked_rotate</span><span class="p">(</span><span class="n">center</span><span class="p">,</span> <span class="n">axis</span><span class="p">,</span> <span class="n">diff</span><span class="p">,</span> <span class="n">mask</span><span class="p">)</span></div>


<div class="viewcode-block" id="Atoms.rattle"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.rattle">[docs]</a>    <span class="k">def</span> <span class="nf">rattle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stdev</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">42</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Randomly displace atoms.</span>

<span class="sd">        This method adds random displacements to the atomic positions,</span>
<span class="sd">        taking a possible constraint into account.  The random numbers are</span>
<span class="sd">        drawn from a normal distribution of standard deviation stdev.</span>

<span class="sd">        For a parallel calculation, it is important to use the same</span>
<span class="sd">        seed on all processors!  &quot;&quot;&quot;</span>

        <span class="n">rs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">RandomState</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span>
        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_positions</span><span class="p">(</span><span class="n">positions</span> <span class="o">+</span>
                           <span class="n">rs</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">scale</span><span class="o">=</span><span class="n">stdev</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">positions</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span></div>

<div class="viewcode-block" id="Atoms.get_distance"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_distance">[docs]</a>    <span class="k">def</span> <span class="nf">get_distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">vector</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return distance between two atoms.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention.</span>
<span class="sd">        vector=True gives the distance vector (from a0 to a1).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">R</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="p">[</span><span class="n">R</span><span class="p">[</span><span class="n">a0</span><span class="p">]]</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="p">[</span><span class="n">R</span><span class="p">[</span><span class="n">a1</span><span class="p">]]</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pbc</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

        <span class="n">D</span><span class="p">,</span> <span class="n">D_len</span> <span class="o">=</span> <span class="n">get_distances</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="n">pbc</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">vector</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">D</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">D_len</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span></div>


<div class="viewcode-block" id="Atoms.get_distances"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_distances">[docs]</a>    <span class="k">def</span> <span class="nf">get_distances</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">vector</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return distances of atom No.i with a list of atoms.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention.</span>
<span class="sd">        vector=True gives the distance vector (from a to self[indices]).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">R</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="p">[</span><span class="n">R</span><span class="p">[</span><span class="n">a</span><span class="p">]]</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="n">R</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pbc</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

        <span class="n">D</span><span class="p">,</span> <span class="n">D_len</span> <span class="o">=</span> <span class="n">get_distances</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="n">pbc</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">vector</span><span class="p">:</span>
            <span class="n">D</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">D</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">D_len</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,)</span>
            <span class="k">return</span> <span class="n">D_len</span></div>


<div class="viewcode-block" id="Atoms.get_all_distances"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_all_distances">[docs]</a>    <span class="k">def</span> <span class="nf">get_all_distances</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">vector</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return distances of all of the atoms with all of the atoms.</span>

<span class="sd">        Use mic=True to use the Minimum Image Convention.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">R</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>

        <span class="n">cell</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pbc</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

        <span class="n">D</span><span class="p">,</span> <span class="n">D_len</span> <span class="o">=</span> <span class="n">get_distances</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="p">,</span> <span class="n">pbc</span><span class="o">=</span><span class="n">pbc</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">vector</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">D</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">D_len</span></div>


<div class="viewcode-block" id="Atoms.set_distance"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_distance">[docs]</a>    <span class="k">def</span> <span class="nf">set_distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">fix</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">add</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">factor</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the distance between two atoms.</span>

<span class="sd">        Set the distance between atoms *a0* and *a1* to *distance*.</span>
<span class="sd">        By default, the center of the two atoms will be fixed.  Use</span>
<span class="sd">        *fix=0* to fix the first atom, *fix=1* to fix the second</span>
<span class="sd">        atom and *fix=0.5* (default) to fix the center of the bond.</span>

<span class="sd">        If *mask* or *indices* are set (*mask* overwrites *indices*),</span>
<span class="sd">        only the atoms defined there are moved (see :meth:`ase.Atoms.set_dihedral`).</span>

<span class="sd">        When *add* is true, the distance is changed by the value given. In combination</span>
<span class="sd">        with *factor* True, the value given is a factor scaling the distance.</span>

<span class="sd">        It is assumed that the atoms in *mask*/*indices* move together</span>
<span class="sd">        with *a1*. If *fix=1*, only *a0* will therefore be moved.&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">add</span><span class="p">:</span>
            <span class="n">oldDist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_distance</span><span class="p">(</span><span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="n">mic</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">factor</span><span class="p">:</span>
                <span class="n">newDist</span> <span class="o">=</span> <span class="n">oldDist</span> <span class="o">*</span> <span class="n">distance</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">newDist</span> <span class="o">=</span> <span class="n">oldDist</span> <span class="o">+</span> <span class="n">distance</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_distance</span><span class="p">(</span><span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">,</span> <span class="n">newDist</span><span class="p">,</span> <span class="n">fix</span><span class="o">=</span><span class="n">fix</span><span class="p">,</span> <span class="n">mic</span><span class="o">=</span><span class="n">mic</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="n">mask</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="n">indices</span><span class="p">,</span> <span class="n">add</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">factor</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="n">R</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>
        <span class="n">D</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">R</span><span class="p">[</span><span class="n">a1</span><span class="p">]</span> <span class="o">-</span> <span class="n">R</span><span class="p">[</span><span class="n">a0</span><span class="p">]])</span>

        <span class="k">if</span> <span class="n">mic</span><span class="p">:</span>
            <span class="n">D</span><span class="p">,</span> <span class="n">D_len</span> <span class="o">=</span> <span class="n">find_mic</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">D_len</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">D</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">())])</span>
        <span class="n">x</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="n">distance</span> <span class="o">/</span> <span class="n">D_len</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">indices</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">indices</span> <span class="o">=</span> <span class="p">[</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span> <span class="p">]</span>
        <span class="k">elif</span> <span class="n">mask</span><span class="p">:</span>
            <span class="n">indices</span> <span class="o">=</span> <span class="p">[</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> <span class="k">if</span> <span class="n">mask</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">]</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="n">a0</span><span class="p">:</span>
                <span class="n">R</span><span class="p">[</span><span class="n">a0</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">x</span> <span class="o">*</span> <span class="n">fix</span><span class="p">)</span> <span class="o">*</span> <span class="n">D</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">R</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-=</span> <span class="p">(</span><span class="n">x</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">fix</span><span class="p">))</span> <span class="o">*</span> <span class="n">D</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>


<div class="viewcode-block" id="Atoms.get_scaled_positions"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_scaled_positions">[docs]</a>    <span class="k">def</span> <span class="nf">get_scaled_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">wrap</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get positions relative to unit cell.</span>

<span class="sd">        If wrap is True, atoms outside the unit cell will be wrapped into</span>
<span class="sd">        the cell in those directions with periodic boundary conditions</span>
<span class="sd">        so that the scaled coordinates are between zero and one.&quot;&quot;&quot;</span>

        <span class="n">fractional</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">(</span><span class="n">complete</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
                                     <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

        <span class="k">if</span> <span class="n">wrap</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">periodic</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">periodic</span><span class="p">:</span>
                    <span class="c1"># Yes, we need to do it twice.</span>
                    <span class="c1"># See the scaled_positions.py test.</span>
                    <span class="n">fractional</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>
                    <span class="n">fractional</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>

        <span class="k">return</span> <span class="n">fractional</span></div>

<div class="viewcode-block" id="Atoms.set_scaled_positions"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.set_scaled_positions">[docs]</a>    <span class="k">def</span> <span class="nf">set_scaled_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scaled</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set positions relative to unit cell.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">scaled</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">(</span><span class="n">complete</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span></div>

<div class="viewcode-block" id="Atoms.wrap"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.wrap">[docs]</a>    <span class="k">def</span> <span class="nf">wrap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">pbc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">eps</span><span class="o">=</span><span class="mf">1e-7</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Wrap positions to unit cell.</span>

<span class="sd">        Parameters:</span>

<span class="sd">        center: three float</span>
<span class="sd">            The positons in fractional coordinates that the new positions</span>
<span class="sd">            will be nearest possible to.</span>
<span class="sd">        pbc: one or 3 bool</span>
<span class="sd">            For each axis in the unit cell decides whether the positions</span>
<span class="sd">            will be moved along this axis.  By default, the boundary</span>
<span class="sd">            conditions of the Atoms object will be used.</span>
<span class="sd">        eps: float</span>
<span class="sd">            Small number to prevent slightly negative coordinates from being</span>
<span class="sd">            wrapped.</span>

<span class="sd">        See also the :func:`ase.geometry.wrap_positions` function.</span>
<span class="sd">        Example:</span>

<span class="sd">        &gt;&gt;&gt; a = Atoms(&#39;H&#39;,</span>
<span class="sd">        ...           [[-0.1, 1.01, -0.5]],</span>
<span class="sd">        ...           cell=[[1, 0, 0], [0, 1, 0], [0, 0, 4]],</span>
<span class="sd">        ...           pbc=[1, 1, 0])</span>
<span class="sd">        &gt;&gt;&gt; a.wrap()</span>
<span class="sd">        &gt;&gt;&gt; a.positions</span>
<span class="sd">        array([[ 0.9 ,  0.01, -0.5 ]])</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">pbc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">pbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pbc</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">wrap_positions</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">positions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cell</span><span class="p">,</span>
                                           <span class="n">pbc</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">eps</span><span class="p">)</span></div>

<div class="viewcode-block" id="Atoms.get_temperature"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_temperature">[docs]</a>    <span class="k">def</span> <span class="nf">get_temperature</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the temperature in Kelvin.&quot;&quot;&quot;</span>
        <span class="n">dof</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">*</span> <span class="mi">3</span>
        <span class="k">for</span> <span class="n">constraint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">:</span>
            <span class="n">dof</span> <span class="o">-=</span> <span class="n">constraint</span><span class="o">.</span><span class="n">removed_dof</span>
        <span class="n">ekin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_kinetic_energy</span><span class="p">()</span>
        <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">ekin</span> <span class="o">/</span> <span class="p">(</span><span class="n">dof</span> <span class="o">*</span> <span class="n">units</span><span class="o">.</span><span class="n">kB</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Check for identity of two atoms objects.</span>

<span class="sd">        Identity means: same positions, atomic numbers, unit cell and</span>
<span class="sd">        periodic boundary conditions.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Atoms</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span>
        <span class="n">b</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">arrays</span>
        <span class="k">return</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> <span class="ow">and</span>
                <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">cell</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="ow">and</span>
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">pbc</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Check if two atoms objects are not equal.</span>

<span class="sd">        Any differences in positions, atomic numbers, unit cell or</span>
<span class="sd">        periodic boundary condtions make atoms objects not equal.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">eq</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__eq__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">eq</span> <span class="ow">is</span> <span class="bp">NotImplemented</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">eq</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="ow">not</span> <span class="n">eq</span>

    <span class="fm">__hash__</span> <span class="o">=</span> <span class="kc">None</span>

<div class="viewcode-block" id="Atoms.get_volume"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.get_volume">[docs]</a>    <span class="k">def</span> <span class="nf">get_volume</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get volume of unit cell.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">number_of_lattice_vectors</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;You have </span><span class="si">{0}</span><span class="s1"> lattice vectors: volume not defined&#39;</span>
                <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">number_of_lattice_vectors</span><span class="p">))</span>
        <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">det</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cell</span><span class="p">))</span></div>

    <span class="k">def</span> <span class="nf">_get_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return reference to positions-array for in-place manipulations.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">_set_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set positions directly, bypassing constraints.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;positions&#39;</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">pos</span>

    <span class="n">positions</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_positions</span><span class="p">,</span> <span class="n">_set_positions</span><span class="p">,</span>
                         <span class="n">doc</span><span class="o">=</span><span class="s1">&#39;Attribute for direct &#39;</span> <span class="o">+</span>
                         <span class="s1">&#39;manipulation of the positions.&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">adsorbate_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the adsorbate information set by one of the surface</span>
<span class="sd">        builder functions. This function is only supplied in order to give</span>
<span class="sd">        a warning if this attribute (atoms.adsorbate_info) is asked for.</span>
<span class="sd">        The dictionary with adsorbate information has been moved to the</span>
<span class="sd">        info dictionary, i.e. atoms.info[&#39;adsorbate_info&#39;].&quot;&quot;&quot;</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;The adsorbate_info dictionary has been moved&quot;</span> <span class="o">+</span>
                      <span class="s2">&quot; inside the info dictionary, i.e. atoms.&quot;</span> <span class="o">+</span>
                      <span class="s2">&quot;info[&#39;adsorbate_info&#39;]&quot;</span><span class="p">,</span> <span class="ne">FutureWarning</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;adsorbate_info&#39;</span><span class="p">]</span>

    <span class="nd">@adsorbate_info</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">adsorbate_info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dct</span><span class="p">):</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;The adsorbate_info dictionary has been moved&quot;</span> <span class="o">+</span>
                      <span class="s2">&quot; inside the info dictionary, i.e. atoms.&quot;</span> <span class="o">+</span>
                      <span class="s2">&quot;info[&#39;adsorbate_info&#39;]&quot;</span><span class="p">,</span> <span class="ne">FutureWarning</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">info</span><span class="p">[</span><span class="s1">&#39;adsorbate_info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dct</span>

    <span class="k">def</span> <span class="nf">_get_atomic_numbers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return reference to atomic numbers for in-place</span>
<span class="sd">        manipulations.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrays</span><span class="p">[</span><span class="s1">&#39;numbers&#39;</span><span class="p">]</span>

    <span class="n">numbers</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_atomic_numbers</span><span class="p">,</span> <span class="n">set_atomic_numbers</span><span class="p">,</span>
                       <span class="n">doc</span><span class="o">=</span><span class="s1">&#39;Attribute for direct &#39;</span> <span class="o">+</span>
                       <span class="s1">&#39;manipulation of the atomic numbers.&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return reference to unit cell for in-place manipulations.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell</span>

    <span class="n">cell</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_cell</span><span class="p">,</span> <span class="n">set_cell</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s1">&#39;Attribute for direct &#39;</span> <span class="o">+</span>
                    <span class="s1">&#39;manipulation of the unit cell.&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return reference to pbc-flags for in-place manipulations.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pbc</span>

    <span class="n">pbc</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_pbc</span><span class="p">,</span> <span class="n">set_pbc</span><span class="p">,</span>
                   <span class="n">doc</span><span class="o">=</span><span class="s1">&#39;Attribute for direct manipulation &#39;</span> <span class="o">+</span>
                   <span class="s1">&#39;of the periodic boundary condition flags.&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write atoms object to a file.</span>

<span class="sd">        see ase.io.write for formats.</span>
<span class="sd">        kwargs are passed to ase.io.write.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">ase.io</span> <span class="k">import</span> <span class="n">write</span>
        <span class="n">write</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">iterimages</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">yield</span> <span class="bp">self</span>

<div class="viewcode-block" id="Atoms.edit"><a class="viewcode-back" href="../../atoms.html#quippy.atoms.Atoms.edit">[docs]</a>    <span class="k">def</span> <span class="nf">edit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Modify atoms interactively through ASE&#39;s GUI viewer.</span>

<span class="sd">        Conflicts leading to undesirable behaviour might arise</span>
<span class="sd">        when matplotlib has been pre-imported with certain</span>
<span class="sd">        incompatible backends and while trying to use the</span>
<span class="sd">        plot feature inside the interactive GUI. To circumvent,</span>
<span class="sd">        please set matplotlib.use(&#39;gtk&#39;) before calling this</span>
<span class="sd">        method.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">ase.gui.images</span> <span class="k">import</span> <span class="n">Images</span>
        <span class="kn">from</span> <span class="nn">ase.gui.gui</span> <span class="k">import</span> <span class="n">GUI</span>
        <span class="n">images</span> <span class="o">=</span> <span class="n">Images</span><span class="p">([</span><span class="bp">self</span><span class="p">])</span>
        <span class="n">gui</span> <span class="o">=</span> <span class="n">GUI</span><span class="p">(</span><span class="n">images</span><span class="p">)</span>
        <span class="n">gui</span><span class="o">.</span><span class="n">run</span><span class="p">()</span></div>


<span class="k">def</span> <span class="nf">string2vector</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">basestring</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;-&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="o">-</span><span class="n">string2vector</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
        <span class="n">w</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">w</span><span class="p">[</span><span class="s1">&#39;xyz&#39;</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">v</span><span class="p">)]</span> <span class="o">=</span> <span class="mf">1.0</span>
        <span class="k">return</span> <span class="n">w</span>
    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">default</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">dflt</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Helper function for setting default values.&quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">return</span> <span class="kc">None</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
        <span class="n">newdata</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">allnone</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">x</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">newdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dflt</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">newdata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
                <span class="n">allnone</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">allnone</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">newdata</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">data</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2008-2016, James Kermode

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>